package fileUtil

import (
	"log"
	"os"
	"strings"
)

var rootPath = GetCurrentPath()

func Write(string2 string, fileName string) {
	f, err := os.OpenFile(fileName, os.O_CREATE|os.O_APPEND|os.O_RDWR, os.ModePerm)
	if err != nil {
		panic("文件读取创建失败:" + err.Error())
		return
	}
	defer f.Close()
	_, _ = f.WriteString(string2)
}

func CreateDir(path string) (error error) {
	file := path
	if !PathExists(file) {
		error = os.MkdirAll(file, os.ModePerm)
	}
	return error
}

func PathExists(path string) bool {
	_, err := os.Stat(path)
	if err == nil {
		return true
	}
	if os.IsNotExist(err) {
		return false
	}
	return false
}

func GetCurrentPath() string {
	dir, err := os.Getwd()
	if err != nil {
		log.Fatal(err)
	}
	return strings.Replace(dir, "\\", "/", -1)
}
